package logic

import (
	"cld-quick-cli/dao"
	"cld-quick-cli/router/parameters"
	"errors"
	"go.uber.org/zap"
	"time"
)

// SaveFileDateBaseLogic 文件存到数据库！
func SaveFileDateBaseLogic(file *parameters.SingleUploadFile) error {
	now := time.Now()
	file.Year = now.Year()
	file.Month = int(now.Month())
	file.Day = now.Day()
	err := dao.InsertSingleFile(file)
	if err != nil {
		return errors.New("文件上传失败！")
	}
	return nil
}

func DownFileLogic(fileId string) (string, error) {
	path, err := dao.GetFilePathByFileId(fileId)
	zap.L().Info(path)
	if err != nil {
		return "", errors.New("文件下载失败")
	}
	return path, nil
}
